import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

/**
 * 自行配置路由*
 *
 * @author LWG
 * @date 2022/7/26 10:28
 * @since 1.0.0
 */
const routes = [
  {
    path: '/',
    name: 'manage',
    component: Home,
    redirect: "/home",//重定向到home页面
    children: [
      {
        path: 'home', name: 'Home',
        component: () => import('@/views/home/indexHoem.vue'),
        meta: {
          keepAlive: true
        }
      },
      // {
      //   path: 'user',
      //   name: 'User',
      //   component: () => import('../views/User.vue'),
      //   meta: {
      //     keepAlive: true
      //   }
      // },
      // {
      //   path: 'announcement',
      //   name: '公告', component: () => import('../views/Announcement.vue')
      // },
      // {
      //   path: 'userLoginLog',
      //   name: '用户登录日志', component: () => import('../views/UserLoginLog.vue'),
      //   meta: {
      //     keepAlive: true
      //   }
      // },
      // {
      //   path: 'userFeedback',
      //   name: '用户反馈', component: () => import('../views/UserFeedback.vue'),
      //   meta: {
      //     keepAlive: true
      //   }
      // },
      {
        path: 'advertising',
        name: '发布广告', component: () => import('@/views/publish'),
        meta: {
          keepAlive: true
        }
      },
      {
        name: '素材管理',
        path: 'image',
        component: () => import('@/views/images')
      },
      // {
      //   path: 'shopManagement',
      //   name: '商品管理', component: () => import('../views/ShopManagement.vue'),
      //   meta: {
      //     keepAlive: true
      //   }
      // },
      {
        path: 'share',
        name: '分享平台管理', component: () => import('@/views/article'),
        meta: {
          keepAlive: true
        }
      },
      // {
      //   path: 'help',
      //   name: '求助平台管理', component: () => import('../views/Help.vue'),
      //   meta: {
      //     keepAlive: true
      //   }
      // },
      {
        name: '评论管理',
        path: 'comment',
        component: () => import('@/views/comment')
      },
      // {
      //   path: 'userDistribution',
      //   name: '用户分布',
      //   component: () => import('../views/UserDistribution.vue'),
      //   meta: {
      //     keepAlive: true
      //   }
      // },
      // {
      //   path: 'newUsers',
      //   name: '新增用户',
      //   component: () => import('../views/NewUsers.vue'),
      //   meta: {
      //     keepAlive: true
      //   }
      // },
      // {
      //   path: 'newUsers2',
      //   name: '新增用户2',
      //   component: () => import('../views/NewUsers2.vue'),
      //   meta: {
      //     keepAlive: true
      //   }
      // },
      // {
      //   path: 'activityOfRegion',
      //   name: '区域活跃度-分享平台', component: () => import('../views/ActivityOfRegion.vue'),
      //   meta: {
      //     keepAlive: true
      //   }
      // },
      // {
      //   path: 'activityOfRegion2',
      //   name: '区域活跃度-互助平台', component: () => import('../views/ActivityOfRegion2.vue'),
      //   meta: {
      //     keepAlive: true
      //   }
      // },
      // {
      //   path: 'numberOAUsers',
      //   name: '活跃用户人数', component: () => import('../views/NumberOAUsers.vue'),
      //   meta: {
      //     keepAlive: true
      //   }
      // },
      // {
      //   path: 'numberOAUsers2',
      //   name: '活跃用户人数2', component: () => import('../views/NumberOAUsers2.vue'),
      //   meta: {
      //     keepAlive: true
      //   }
      // },
      {
        path: 'person',
        name: '管理员信息', component: () => import('@/views/settings'),
        meta: {
          keepAlive: true
        }
      }
    ]
  },
  {
    path: '/about',
    name: 'about',
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login')
  },

]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

// to:即将进入的路由对象
// from:当前导航即将离开额路由
// next:进行管道中的一个钩子，如果执行完了，那么导航的状态就是 confirmed，否则为false，终止导航

// router.beforeEach((to, from, next) => {
//     console.log(this)
//     if (to.path === '/login') {
//         //如果去登录页面，就放行
//         next();
//     } else if (JSON.parse(localStorage.getItem("user")) != null) {
//         console.log(JSON.parse(localStorage.getItem("user")))
//         //如果登录了，就放行
//         next();
//     } else {
//         //如果没有登录，那么就跳转带登录页面
//         next("/login");
//     }
// })

export default router
